﻿using Autofac;
using Smart.Admin.Domain.GlobalVar;
using Smart.Admin.Domain.Repository;
using Microsoft.EntityFrameworkCore;
using System.Reflection;

namespace Smart.Admin.Api.AutofacConfig
{
    /// <summary>
    /// Autofac 默认模块配置
    /// </summary>
    public class DefaultModule : Autofac.Module
    {
        //Autofac容器
        protected override void Load(ContainerBuilder builder)
        {
            //程序集注入
            var Domain = Assembly.Load("Smart.Admin.Domain");

            //根据名称约定，实现领域
            builder.RegisterAssemblyTypes(Domain)
              .Where(t => t.Name.EndsWith("Service"))
             .AsSelf();

            builder.RegisterBuildCallback(scope =>
            {
                AutofacVar.container = (IContainer)scope;
            });
        }
    }
}
